package Proj_pack;

import java.util.Collection;
import java.util.concurrent.LinkedBlockingDeque;


public class SwitchingQueue{
	LinkedBlockingDeque<Mash> first =new LinkedBlockingDeque<Mash>();
	LinkedBlockingDeque<Mash> second= new LinkedBlockingDeque<Mash>();


	public synchronized void add(Mash m){
		second.add(m);
	}

	public synchronized void addAll(Collection<Mash> mashes){
		first.addAll(mashes);
	}
	public synchronized Mash poll(){
		return first.poll();
	}
	public synchronized void switchQueue(){
		if(second.isEmpty() && first.isEmpty()){
			Thread.currentThread().interrupt();
		}
		else{
			LinkedBlockingDeque<Mash> temp = first;
			first=second;
			second=temp;
		}
	}
}
